package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TaskDataRel;
import com.ruoyi.system.service.ITaskDataRelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务数据关联Controller
 * 
 * @author wsx
 * @date 2025-07-30
 */
@Controller
@RequestMapping("/system/taskDataRel")
public class TaskDataRelController extends BaseController {
    private String prefix = "system/taskDataRel";

    @Autowired
    private ITaskDataRelService taskDataRelService;

    @RequiresPermissions("system:taskDataRel:view")
    @GetMapping()
    public String taskDataRel() {
        return prefix + "/taskDataRel";
    }

    /**
     * 查询任务数据关联列表
     */
    @RequiresPermissions("system:taskDataRel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskDataRel taskDataRel) {
        startPage();
        List<TaskDataRel> list = taskDataRelService.selectTaskDataRelList(taskDataRel);
        return getDataTable(list);
    }

    /**
     * 导出任务数据关联列表
     */
    @RequiresPermissions("system:taskDataRel:export")
    @Log(title = "任务数据关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaskDataRel taskDataRel) {
        List<TaskDataRel> list = taskDataRelService.selectTaskDataRelList(taskDataRel);
        ExcelUtil<TaskDataRel> util = new ExcelUtil<TaskDataRel>(TaskDataRel.class);
        return util.exportExcel(list, "任务数据关联数据");
    }

    /**
     * 新增任务数据关联
     */
    @RequiresPermissions("system:taskDataRel:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存任务数据关联
     */
    // @RequiresPermissions("system:taskDataRel:add")
    @Log(title = "任务数据关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaskDataRel taskDataRel) {
        taskDataRelService.saveTaskDataRel(taskDataRel.getTaskId(), String.valueOf(
                taskDataRel.getDataId()));
        return AjaxResult.success();
    }

    /**
     * 修改任务数据关联
     */
    @RequiresPermissions("system:taskDataRel:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TaskDataRel taskDataRel = taskDataRelService.selectTaskDataRelById(id);
        mmap.put("taskDataRel", taskDataRel);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务数据关联
     */
    @RequiresPermissions("system:taskDataRel:edit")
    @Log(title = "任务数据关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaskDataRel taskDataRel) {
        return toAjax(taskDataRelService.updateTaskDataRel(taskDataRel));
    }

    /**
     * 删除任务数据关联
     */
    @RequiresPermissions("system:taskDataRel:remove")
    @Log(title = "任务数据关联", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(taskDataRelService.deleteTaskDataRelByIds(ids));
    }
}
